## Definiraj instancu SET-COVER problema opisano matricom incidencije
from random import randint
import sys


class inputGen:
    """input generator class for LP solver """
    def __init__(self,n,m):
        self.n = n
        self.m = m

        self.A = []
        self.c = []
        self.b = []

        # define matrix
        for i in range(0,n*m):
            randomBit = randint(0,1)
            self.A.append(randomBit)
        # define cost vector
#        for i in range(0,m):
#            randomCost = randint(1,100)
#            self.c.append(randomCost);
        # define demand vector
#        for i in range(0,n):
#            randomDemand = randint(1,self.A[i*m:(i+1)*m].count(1))
#            self.b.append(randomDemand);




    def sparseForm(self,outFile):
        self.sparseFile = open(outFile,'w')
        self.sparseFile.write("%d %d %d\n" % (self.n,self.m,self.A.count(1)))

        for row in range(0,self.n):
            for col in range(0,self.m):
                self.sparseFile.write("%d %d %g\n" % (row,col,self.A[col+row*self.m]))

#        self.sparseFile.write("\n")
#        for val in self.c:
#            self.sparseFile.write("%g " % val)

#        self.sparseFile.write("\n")
#        for val in self.b:
#            self.sparseFile.write("%d " % val)

        #close the file ...
        self.sparseFile.close()


    def denseForm(self,outFile):
        self.denseFile = open(outFile,'w')
        self.denseFile.write("%d %d\n" % (self.n,self.m))

        cols = 0

        for a in self.A:
            self.denseFile.write("%g " % a)
            cols = cols+1
            if cols==M:
                self.denseFile.write("\n")
                cols = 0

 #       self.denseFile.write("\n")
#        for val in self.c:
#            self.denseFile.write("%g " % val)

#        self.denseFile.write("\n")
#        for val in self.b:
#            self.denseFile.write("%d " % val)

        #close the file ...
        self.denseFile.close()




# main program
N = 10;
M = 10;

if len(sys.argv)>1:
     M = int(sys.argv[1])
     N = int(sys.argv[2])


input = inputGen(N,M)
input.sparseForm('inputData%dx%d.dat' % (N,M))


